package com.alittle.core.view;

import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.alittle.R;
import com.android.volley.Request;


/**
 * @author wom
 *         只负责View，何时开始，何时结束
 *         <br/>
 *         请求访问等逻辑在外面
 */
public class ModalIndicator extends AlertDialog {

    private Request request;
    private TextView vMessage;

    public ModalIndicator(Context context) {
        super(context);
        View view = LayoutInflater.from(context).inflate(R.layout.passenger_dialog_loading, null, false);
//        setView(view);
//        setContentView(R.layout.passenger_dialog_loading);
        vMessage = (TextView) view.findViewById(R.id.parents_style_content);
        setCanceledOnTouchOutside(false);
    }

    public final ModalIndicator setIndicateMessage(String message) {
        vMessage.setText(message);
        return this;
    }

    public final ModalIndicator bindRequest(Request request) {
        this.request = request;
        return this;
    }

    @Override
    public void dismiss() {
        if (request != null && !request.isCanceled()) {
            request.cancel();
            request = null;
        }
        super.dismiss();
    }

}
